#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2021-11-28 17:25
from time import sleep

from homework.task_selenium.common.base_page import BasePage
from homework.task_selenium.page_locators.add_member_page_locators import *
from homework.task_selenium.page_objects.contracts_page import ContractsPage


class AddMemberPage(BasePage):
    # todo 添加url
    # _base_url = "https://work.weixin.qq.com/wework_admin/frame#contacts"

    def add_member(self, member_name, account, phone_num):
        """
        成功添加成员
        :param member_name: 用户名称
        :param account: 账号
        :param phone_num: 电话号码
        :return: 成员列表页面
        :rtype: PageObject
        """
        self.find(user_name_locator).send_keys(member_name)
        self.find(account_locator).send_keys(account)
        self.find(phone_locator).send_keys(phone_num)
        self.find(save_locator).click()
        sleep(2)
        # 返回成员列表页面，以便后续获取数据做校验
        return ContractsPage(self.driver)

    def add_member_fail_by_name(self):
        """
        用户名为空,则页面给出提示
        :return: 提示信息列表
        """
        # 跳过用户名，点击账号输入框
        self.find(account_locator).click()
        tips_ele = self.finds(tips_locator)
        tip_texts = [tip_ele.text for tip_ele in tips_ele]
        return tip_texts

    def add_member_fail_by_account(self, exist_account):
        """
        账号重复，则页面给出提示
        :param exist_account: 已存在的账号
        :return: 提示信息列表
        """
        # 跳过用户名，点击账号输入框
        self.find(account_locator).send_keys(exist_account)
        self.find(user_name_locator).click()
        sleep(1)
        tips_ele = self.finds(tips_locator)
        tip_texts = [tip_ele.text for tip_ele in tips_ele]
        return tip_texts

    def add_member_fail_by_phone(self, exist_phone_num):
        """
        手机号重复，则页面给出提示
        :param exist_phone_num: 已存在的手机号码
        :return: 提示信息列表
        """
        # 跳过用户名，点击账号输入框
        self.find(phone_locator).send_keys(exist_phone_num)
        # 为了使输入框失去焦点
        self.find(user_name_locator).click()
        sleep(1)
        tips_ele = self.finds(tips_locator)
        tip_texts = [tip_ele.text for tip_ele in tips_ele]
        return tip_texts

    def add_member_and_continue(self, member_name, account, phone_num):
        """
        添加成员后继续添加
        :param member_name: 用户名称
        :param account: 账号
        :param phone_num: 电话号码
        :return: 成员添加页面
        :rtype: PageObject
        """
        self.find(user_name_locator).sen_dkeys(member_name)
        self.find(account_locator).send_keys(account)
        self.find(phone_locator).send_keys(phone_num)
        self.find(save_continue_locator).click

        return AddMemberPage(self.driver)

    def add_member_and_cancel(self, member_name, account, phone_num):
        """
        添加成员后继续添加
        :param member_name: 用户名称
        :param account: 账号
        :param phone_num: 电话号码
        :return: 成员列表页面
        :rtype: PageObject
        """
        self.find(user_name_locator).send_keys(member_name)
        self.find(account_locator).send_keys(account)
        self.find(phone_locator).send_keys(phone_num)
        self.find(save_continue_locator).click

        # 返回成员列表页面，以便后续获取数据做校验
        return ContractsPage(self.driver)
